<template>
  <div class="login">
    <van-form required="auto">
      <van-field v-model="username" :rules="[{ required: true }]" label="账号" />
      <van-field v-model="password" type="password" :rules="[{ required: true }]" label="密码" />
    </van-form>
    <van-radio-group v-model="checked">
      <van-radio shape="square" name="1">记住密码</van-radio>
    </van-radio-group>
    <van-button size="large" type="primary" @click="login">登录</van-button>
    <span><a href="">找回密码</a> | 还没有注册账号？<a href="./login">立即注册</a></span>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { getUserInfoList} from '@/api'
import { useRouter } from 'vue-router'

const router = useRouter()
const username = ref<string>('dashuaige')
const password = ref<string>('123456')
const checked = ref<boolean>(false)



async function login() {
  // console.log('登录');
  // console.log('username',username.value);
  const {data} : any = await getUserInfoList()
    // console.log('result', data[0].params.username)
    for(let i = 0; i<data.length;i++){
      if(username.value===data[i].params.username && password.value === data[i].params.password) {
        // console.log('登入成功');
        window.localStorage.setItem('token','Token')
        router.back()
        return
      }
    }
    console.log('登入失败');
    
}
</script>

<style lang="scss" scoped>
.van-radio {
  margin: 20px;
}
span {
  display: block;
  margin: 10px 0 20px 48px;
}
</style>
